package forum.command;

import forum.entities.Topic;
import forum.entities.User;
import forum.services.UserService;

public class PostMessageCommand implements Command {

    private String postContains;
    private Topic topic;
    private User user;

    private UserService userService = new UserService();

    @Override
    public void execute() {
        userService.postMessage(user, topic, postContains);
    }

    @Override
    public void setParameters(String... args) {
        if (args.length != 1) {
            throw new IllegalArgumentException ("Incorrect number of arguments");
        }
        postContains = args[0];
    }

    @Override
    public void setContext(CommandContext context) {
        user = context.getUser();
        topic = context.getTopic();
    }

    @Override
    public void updateContext(CommandContext context) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String help() {
        return "Type post | %message%";
    }
}
